'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.logFn = exports.logWithTrace = exports.logStringify = exports.logReturn = exports.log = undefined;

var _typeof2 = require('babel-runtime/helpers/typeof');

var _typeof3 = _interopRequireDefault(_typeof2);

var _safeStringify = require('./safeStringify');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var log = exports.log = function log() {
    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
    }

    console.log('---' + new Date() + '---');
    var msg = [];
    for (var i = 0, il = args.length; i < il; i++) {
        if ((0, _typeof3.default)(args[i]) === 'object') {
            msg.length > 0 && console.log(msg.join(' '));
            console.log(args[i]);
            msg = [];
            continue;
        }
        msg.push(args[i]);
    }
    msg.length > 0 && console.log(msg.join(' '));
};

var logReturn = exports.logReturn = function logReturn() {
    var _ref;

    log.apply(undefined, arguments);
    return _ref = arguments.length - 1, arguments.length <= _ref ? undefined : arguments[_ref];
};
var logStringify = exports.logStringify = function logStringify() {
    for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
        args[_key2] = arguments[_key2];
    }

    var _args = [];
    for (var i = 0, il = args.length; i < il; i++) {
        if ((0, _typeof3.default)(args[i]) === 'object') {
            _args.push((0, _safeStringify.safeStringify)(args[i]));
            continue;
        }
        _args.push(args[i]);
    }
    return log.apply(undefined, _args);
};
var logWithTrace = exports.logWithTrace = function logWithTrace() {
    log.apply(undefined, arguments);
    console.trace();
};
var logFn = exports.logFn = function logFn(tip, fn) {
    for (var _len3 = arguments.length, logArgs = Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
        logArgs[_key3 - 2] = arguments[_key3];
    }

    return function () {
        for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
            args[_key4] = arguments[_key4];
        }

        var rst = fn.call.apply(fn, [this].concat(args));
        log.apply(undefined, [tip].concat(args, [rst], logArgs));
        return rst;
    };
};
exports.default = log;